package com.example.communication;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;

public class Activity22 extends Activity {
	private TextView textView1;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_activity22);
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		textView1 = (TextView)findViewById(R.id.TextView1);
		Intent it = this.getIntent();
		Bundle b = it.getExtras();
		String message = String.format ("%s is %d years old.",b.getString("NAME"),b.getInt("AGE"));
		textView1.setText(message);
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		//super.onBackPressed();
		Log.i ("ACT_COMMU","BACK");
		AlertDialog.Builder dialog = new AlertDialog.Builder(this);
		dialog.setTitle("Message");
		dialog.setMessage("Are U sure?");
		dialog.setPositiveButton("Go", new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
		Activity22.super.onBackPressed();
		}
		});
		dialog.setNegativeButton("Cancel",
		new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
		//Do NOTHING
		}
		});
		dialog.show();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity22, menu);
		return true;
	}

}
